package com.lgh.hotel.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lgh.hotel.dao.mapper.TempMapper;
import com.lgh.hotel.dao.pojo.GuestTemp;
import com.lgh.hotel.service.TempServer;
import com.lgh.hotel.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TempServiceImpl  extends ServiceImpl<TempMapper, GuestTemp> implements TempServer{
    @Autowired
    TempMapper tempMapper;


    @Override
    public Result tempToUser() {
        LambdaQueryWrapper<GuestTemp> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(GuestTemp::getUserId,0);
        List<GuestTemp> tables = tempMapper.selectList(queryWrapper);
        return Result.succ(tables);
    }

    @Override
    public Result select(GuestTemp params) {
        LambdaQueryWrapper<GuestTemp> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(null!=params.getUserId(),GuestTemp::getUserId,params.getUserId());
        queryWrapper.orderByDesc(GuestTemp::getId);
        List<GuestTemp> tables = tempMapper.selectList(queryWrapper);
        return Result.succ(tables);
    }

    @Override
    public void insert(GuestTemp params) {
        tempMapper.insert(params);
    }

    @Override
    public void update(GuestTemp params) {
        LambdaQueryWrapper<GuestTemp> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(null!=params.getUserId(),GuestTemp::getUserId,params.getUserId());
        queryWrapper.eq(null!=params.getTempTime(),GuestTemp::getTempTime,params.getTempTime());
        tempMapper.update(params,queryWrapper);
    }

    @Override
    public void delete(GuestTemp params) {

    }

//    @Override
//    public void delete(GuestTemp params) {
//        tempMapper.deleteById(params.getId());
//    }
}
